package simple

import "strings"

func wordPattern(pattern string, s string) bool {

	patternSlice := strings.Split(pattern, "")
	sSlice := strings.Split(s, " ")
	if len(patternSlice) != len(sSlice) {
		return false
	}

	pToSMap := make(map[string]string)
	sMap := make(map[string]string)
	for i := 0; i < len(patternSlice); i++ {
		if val, ok := pToSMap[patternSlice[i]]; ok {
			if sSlice[i] != val {
				return false
			}
		} else {
			pToSMap[patternSlice[i]] = sSlice[i]
		}

		if val, ok := sMap[sSlice[i]]; ok {
			if patternSlice[i] != val {
				return false
			}
		} else {
			sMap[sSlice[i]] = patternSlice[i]
		}
	}

	return true
}
